package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class DatabaseDao {

	public static Connection getConnection() {
		
	
		String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		
		// String database = "Sinawler2";
		// String dbURL =
		// "jdbc:sqlserver://59.64.158.30:1433;DatabaseName="+database;
		// String userName = "sa";
		// String userPwd = "bnrc609";

		
		//String database = "Sinawler2";
		String database = "Sinaweibo";
		String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=" + database;
		String userName = "sa";
		String userPwd = "bnrc";

		Connection dbConn = null;
		try {
			Class.forName(driverName);
			dbConn = DriverManager.getConnection(dbURL, userName, userPwd);

		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("failed!");
			
		}
		return dbConn;
	}

	public static void updateData(String sql) {
		try {
			Statement stmt = DatabaseDao.getConnection().createStatement();
			stmt.executeUpdate(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
}
